package com.gg.cart.contorller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;

import com.gg.cart.service.CartService;
import com.gg.entity.User;

import helpers.baseservlet.BaseServlet;
import povos.CartFruitPovo;

@WebServlet("/cart/AddCartServlet")
public class AddCartServlet extends BaseServlet {
	@Autowired
	private CartService cartService;
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int  fid =Integer.parseInt(request.getParameter("fid"));
		int  count=Integer.parseInt(request.getParameter("count"));
		User user =(User) request.getSession().getAttribute("user");
		String uid=user.getUid();
		cartService.addCart(fid,count,uid);
		List<CartFruitPovo> povos =cartService.getCartFruitPovoByUid(uid);
		request.getSession().setAttribute("cartpovos",povos);
		response.sendRedirect("/fruits/showcart.jsp");
	}

	

}
